package br.com.lucasddaniel.inbuzios.dao;

/**
 * Classe de cria�ao das tabelas.
 * 
 * @author ldsm
 * 
 */
public class PacoteEsquemaBanco {

    /** Define a vers�o do banco. */
    public static final int CURRENT_DATABASE_VERSION = 1;

    /** Nome da base da aplica��o. */
    public static final String DATA_BASE_NAME = "inbuzios_db";

    /** Tabela de passeio. */
    public static final String TABLE_NAME = "tb_pacote";

    /** Chaves de tabelas como ex: chave estrangeira, etc... */
    public static final String TABLE_CONSTRAINTS = " FOREIGN KEY(passeio_id) REFERENCES tb_passeio(id) DEFERRABLE INITIALLY DEFERRED";

    /** SQL de cria��o da tabela de passeio */
    public static final String SQL_CREATE_TABLE;

    /**
     * Cria��o da tabela de passeio.
     */
    public static final TableColumn TABLE_COLUMNS[] = {
    	new TableColumn("id", "INTEGER PRIMARY KEY AUTOINCREMENT,"), 
    	new TableColumn("nome_pacote", "TEXT,"), 
    	new TableColumn("preco", "REAL,"),
            new TableColumn("preco_dolar", "REAL,"), 
            new TableColumn("data_hora_passeio", "DATE,"), 
            new TableColumn("transporte", "TEXT,"), 
            new TableColumn("quantidade", "NUMBER,"),
            new TableColumn("total", "REAL,"), 
            new TableColumn("tipo_moeda", "TEXT,"), 
            new TableColumn("passeio_id", "INTEGER, ")};

    /* Bloco de inicializa��o */
    static {
        final String CREATE_TABLE = "CREATE TABLE ";

        StringBuilder builder = new StringBuilder();

        SQL_CREATE_TABLE =
                builder.append(CREATE_TABLE).append(TABLE_NAME).append("(").append(TABLE_COLUMNS[0]).append(TABLE_COLUMNS[1]).append(TABLE_COLUMNS[2]).append(TABLE_COLUMNS[3])
                        .append(TABLE_COLUMNS[4]).append(TABLE_COLUMNS[5]).append(TABLE_COLUMNS[6]).append(TABLE_COLUMNS[7]).append(TABLE_COLUMNS[8]).append(TABLE_COLUMNS[9])
                        .append(TABLE_CONSTRAINTS).append(")").toString();
        builder.setLength(0);
    }

    public static class TableColumn {
        String columnName;
        String columnType;

        public TableColumn(String name, String type) {
            this.columnName = name;
            this.columnType = type;
        }

        public String getColumnName() {
            return this.columnName;
        }

        public String toString() {
            return columnName + " " + columnType;
        }
    }
}
